package com.yyq.sos.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.yyq.adms.sysmanage.dao.impl.DataDictionaryDaoImpl;
import com.yyq.adms.sysmanage.pojo.DataDictionary;
import com.yyq.servlets.ApplicationContextHandle;

public class PlateFormUtil {

	private static Map map = new HashMap();
	private final static PlateFormUtil instance = new PlateFormUtil();
	
	private PlateFormUtil(){
		DataDictionaryDaoImpl dao = (DataDictionaryDaoImpl)ApplicationContextHandle.getBean("dataDictionaryDao");
		String hql = "from DataDictionary where key='platform'";
		List list = dao.search(hql);
		for(int i=0; i<list.size(); ++i){
			DataDictionary obj = (DataDictionary)list.get(i);
			map.put(obj.getText(),obj.getValue());
		}
	}
	
	public static PlateFormUtil getInstances(){
		return instance;
	}
	
	public List<DataDictionary> getPlateForms(){
		List<DataDictionary> dds = new ArrayList<DataDictionary>();
		Set set = map.keySet();
		for (Object obj : set) {
			DataDictionary dd = new DataDictionary();
			dd.setText(obj.toString());
			dd.setValue(obj.toString());
			dds.add(dd);
		}
		return dds;
	}
	
	public boolean existKey(String param){
		return map.containsKey(param);
	}
	
	public String getValue(String param)
	{
		return (String)map.get(param);
	}
	
	public void add(String param,String value){
		map.put(param, value);
	}
	
	public void delete(String param)
	{
		map.remove(param);
	}
}
